package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleCategoryParam;
import com.tarena.lbs.content.pojo.query.ArticleCategoryQuery;
import com.tarena.lbs.content.pojo.vo.ArticleCategoryVO;
import com.tarena.lbs.content.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理文章分类 业务模块功能
 */
@Tag(name = "文章分类管理")
@RestController
@Slf4j
public class CategoryController {


@Autowired
private CategoryService categoryService;

    /**
     * 插入分类
     * ~
     * @return
     */
    @Operation(summary = "文章分类列表查询")
    @GetMapping("/admin/content/category/list")
    public Result<PageResult<ArticleCategoryVO>> pageList(){
        PageResult<ArticleCategoryVO> voPage = categoryService.pageList();
        return new Result<>(voPage);
    }

    @Operation(summary = "文章分类保存")
    @PostMapping("/admin/content/category/insert")
    public Result<Void> saveES(ArticleCategoryParam  param){
        log.debug("文章分类保存业务处理,入参:{}",param);
        categoryService.save(param);
        return Result.success();
    }

    @Operation(summary = "文章分类更新")
    @PostMapping("/admin/content/category/update")
    public Result<Void> updateES(ArticleCategoryParam param){
        log.debug("文章分类更新业务处理,入参:{}",param);
        categoryService.save(param);
        return Result.success();
    }

    @Operation(summary = "文章分类删除")
    @PostMapping("/admin/content/category/delete")
    public Result<Void> deleteES(@RequestBody ArticleCategoryParam param){
        log.debug("文章分类删除业务处理,入参:{}",param);
        categoryService.delete(param.getId());
        return Result.success();
    }

}
